package com.stars.easyms.base.interceptor;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * <p>className: EasyMsCglibMethodInterceptor</p>
 * <p>description: 方法拦截器接口</p>
 *
 * @author guoguifang
 * @version 1.7.3
 * @date 2021/3/25 7:45 下午
 */
public interface EasyMsCglibMethodInterceptor extends MethodInterceptor {

    @Override
    default Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        if (Object.class.equals(method.getDeclaringClass())) {
            return proceed(o, method, objects);
        }

        return intercept(o, method, objects);
    }

    /**
     * 拦截不通过时的执行方法
     */
    default Object proceed(Object o, Method method, Object[] objects) throws Throwable {
        return method.invoke(o, objects);
    }

    /**
     * 拦截成功后执行的方法
     */
    Object intercept(Object o, Method method, Object[] objects) throws Throwable;

}